﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BOHVote.BLL;
using BOHVote.Common;

namespace BOH.DataManagement
{
    public partial class ApplyPeriodList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PeriodBind();
            }
        }

        protected void butSearch_Click(object sender, EventArgs e)
        {
            PeriodBind();
        }
        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            PeriodBind();
        }
        protected void butDelet_Click(object sender, EventArgs e)
        {
            if (hiddenSelected.Value.Trim().Length > 0 && hiddenSelected.Value.Trim() != ",")
            {
                string[] arrPeriodID = hiddenSelected.Value.Trim().Split(new char[] { ',' });
                foreach (string PeriodID in arrPeriodID)
                {
                    if (PeriodID.Trim().Length > 0)
                    {
                        PeriodClass.DeletePeriodByID(PeriodID);
                    }
                }
                PeriodBind();
            }
            
        }

        public void PeriodBind()
        {
            DataSet dst = PeriodClass.getPeriod(drpStatus.SelectedValue, txtApplyPeriodName.Text.Trim(), drpArchivesStatus.SelectedValue);

            BindPeriodList(dst);
        }


        public void BindPeriodList(DataSet dst)
        {
            AspNetPager1.RecordCount = dst.Tables[0].Rows.Count;
            if (AspNetPager1.RecordCount != 0)
            {
                labNoRecord.Visible = false;
                AspNetPager1.Visible = true;
                PagedDataSource pds = new PagedDataSource();
                pds.DataSource = dst.Tables[0].DefaultView;
                pds.AllowPaging = true;
                pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                pds.PageSize = AspNetPager1.PageSize;
                PeriodViewList.DataSource = pds;
                PeriodViewList.DataBind();
            }
            else
            {
                PeriodViewList.DataSource = null;
                PeriodViewList.DataBind();
                AspNetPager1.Visible = false;
                labNoRecord.Visible = true;
            }
        }
        public string FormatDateToString(string strDate)
        {
            string returnValue = string.Empty;
            if(!string.IsNullOrEmpty(strDate))
            {
                returnValue = common.ChangeDateFormatToString(Convert.ToDateTime(strDate));
            }
            return returnValue;
        }
        public string getArchivesStatus(string ArchivesStatus)
        {
            string returnvalue = string.Empty;
            switch (ArchivesStatus)
            {
                case "I":
                    returnvalue = "<font color='red'>未编号</font>";
                    break;
                case "S":
                    returnvalue = "移交完成";
                    break;
                case "N":
                    returnvalue = "编号完成";
                    break;
                default:
                    break;
            }

            return returnvalue;
        }
        public string getStatus(string status)
        {
            string returnvalue = string.Empty;
            switch (status)
            {
                case "A":
                    returnvalue = "激活";
                    break;
                case "C":
                    returnvalue = "已结束";
                    break;
                case "N":
                    returnvalue = "<font color='red'>未激活</font>";
                    break;
                default:
                    break;
            }

            return returnvalue;
        }


    }
}
